package com.mengniu.commerce.collect.service;

import com.mengniu.commerce.common.core.exception.ServiceException;
import com.mengniu.commerce.common.core.utils.Md5Utils;
import com.mengniu.commerce.common.core.utils.SpringUtils;


/**
 * @author: dgyu-398305246@qq.com
 * @createTime: 2023年11月28 12:47:24
 * @description: 有赞推送数据策略
 */
public interface IPushStrategy {

    String BASE_NAME = "PushStrategy";

    String CLIENT_ID = "062f406ee377bd9653"; //应用的 client_id

    String CLIENT_SECRET = "4a7803eef189a67c4e4b4b09b8e38cd4";//应用的 client_secret

    /**
     * 推送
     */
    static Object push(String entity, String eventType, String eventSign) {
        /*String sign = Md5Utils.MD5(CLIENT_ID + entity + CLIENT_SECRET);
        if (!sign.equals(eventSign)) {
            throw new ServiceException("消息不合法!");
        }*/
        // 消息的类型 调用不同实现
        String beanName = eventType + BASE_NAME;
        if (!SpringUtils.containsBean(beanName)) {
            throw new ServiceException("消息类型为实现，eventType:"+eventType);
        }
        IPushStrategy instance = SpringUtils.getBean(beanName);
        return instance.push(entity);
    }


    /**
     * 推送
     */
    Object push(String entity);

}
